package math;

/**
 * Created by fengliejv on 2018/1/3.
 */
public class Pow50 {
    public double myPow(double x, int n) {
        if(n==0){
            return 1;
        }
        if(n==1){
            return x;
        }
        boolean flag = true;
        double t = 1;
        if(n<0){
            if(n==Integer.MIN_VALUE){
                t = x;
                n=n+1;
            }
            flag = false;
            n=-n;
        }
        double v = myPow(x, n / 2);
        if(n%2==0){
            return flag?v*v*t:1/(t*v*v);
        }else {
            return flag?v*v*x*t:1/(t*v*v*x);
        }
    }
}
